package main

import "C"
import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"net/http"
	_ "sdapiproject/docs"
	"sdapiproject/handlers"
	"sdapiproject/redis_func"
	"sdapiproject/task_process"
	"sdapiproject/utils"
)

//	@title			SDAPI
//	@version		1.0
//	@description	SDAPI接口文档
//	@termsOfService	https://razeen.me

//	@contact.name	Lumos
//	@contact.url	https://razeen.me
//	@contact.email	me@razeen.me

// @host	103.159.125.149:19019
// @BasePath

func main() {
	//103.159.125.149
	// 初始化配置
	utils.InitConfig()
	// 初始化Redis
	redis_func.Init()
	// 初始化任务队列
	task_process.StartServer()

	r := gin.Default()

	config := cors.DefaultConfig()
	config.AllowAllOrigins = true
	r.Use(cors.New(config))

	r.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	// 这将启动一个静态文件服务，将 D:\\sdwebuiresult\\ 目录下的文件提供给 /images/* 路径。
	r.StaticFS("/images", http.Dir(utils.Cfg.DownloadPath.Path))

	// 创建一个路由组
	txt2ImgGroup := r.Group("/sdtxt2img")
	{
		txt2ImgGroup.POST("/", handlers.Txt2ImgRequest)
		txt2ImgGroup.POST("/getresult", handlers.GetTxt2ImgResult)
		txt2ImgGroup.POST("/progress", handlers.ProgressRequest)
		txt2ImgGroup.POST("/interrupt", handlers.InterruptRequest)
		txt2ImgGroup.POST("/gettxt2imgstatus", handlers.GetTxt2ImgStatus)
	}
	port := utils.Cfg.Port
	r.Run(port)
}
